<template>
  <el-menu :default-active="activeIndex2" class="el-menu-demo" style="display: flex; justify-content: center"
    mode="horizontal" router background-color="white" text-color="black" active-text-color="#ffd04b"
    @select="handleSelect">
    <img src="@/assets/images/logo.jpg" style="width: 45px; height: 59px; cursor: pointer;" @click="()=>{router.push('/user/home')} ">
    <el-menu-item index="/user/home">首页</el-menu-item>
    <el-menu-item index="/user/help">助农专区</el-menu-item>
    <el-menu-item index="/user/goods">农产品</el-menu-item>
    <el-menu-item index="/user/group">团购</el-menu-item>
    <el-sub-menu index="4">
      <template #title>
        <div class="demo-type">
          <el-avatar src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
        </div>
      </template>
      <el-menu-item index="/user/Login" v-if="true">
        <el-icon>
          <UserFilled />
        </el-icon>
        用户登录
      </el-menu-item>
      <el-menu-item index="/user/loginOut" v-else>退出登录</el-menu-item>
      <el-menu-item index="/user/settings">
        <el-icon>
          <Setting />
        </el-icon>
        个人设置
      </el-menu-item>
      <el-menu-item index="/user/allOrder">
        <el-icon>
          <Shop />
        </el-icon>
        订单记录
      </el-menu-item>
      <el-menu-item index="/user/orderDetail">
        <el-icon>
          <Goods />
        </el-icon>
        订单详情
      </el-menu-item>
    </el-sub-menu>
  </el-menu>
</template>

<script setup lang="ts">
import { defineComponent } from "vue";
import { useRouter } from "vue-router";
import { ref } from "vue";
const router = useRouter();

router.afterEach((to) => {
  activeIndex2.value = to.path;
});
const activeIndex2 = ref("2");
const handleSelect = (key: string, keyPath: string[]) => {
  console.log(key, keyPath);
};
defineComponent({
  name: "GlobalHeader",
  props: {
    msg: String,
  },
});
</script>

<style scoped>
.centered-menu {
  display: flex;
  justify-content: center;
  align-items: center;
}

/* 头像 */
.demo-type {
  display: flex;
}

.demo-type > div {
  flex: 1;
  text-align: center;
}

.demo-type > div:not(:last-child) {
  border-right: 1px solid var(--el-border-color);
}
</style>
